<!DOCTYPE HTML>
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script type="text/javascript">
	function fnGetRestTime(target)
	{
		//var 
		
		var curTm = $("#"+target).text();
		var restTm = "";
		if (curTm && curTm != "END")
		{
			var restSec = getTotalSec(curTm);
			if (restSec > 0)
			{
				restTm = fnSec2Min(getTotalSec(curTm)-1);
			}
			else
			{
				restTm = "END";
				$("#"+target).css("border","1px #999 solid");
			}
			 $("#"+target).text(restTm);
		}
		//alert(getTotalSec(curTm));
		if (curTm != "END")
		{
			setTimeout("fnGetRestTime('"+target+"')", 1000);
		}
		return;
	}

	fnGetRestTime("a");
	function fnSec2Min(tm)
	{
		var hr = 0;
		var min = 0;
		var sec = 0;
		var restSec = 0;
		hr = Math.floor(tm / (60 * 60));
		restSec = tm - (hr*60*60);
		min = Math.floor(restSec/60);
		sec = restSec - (min*60);
		if (hr==0) hr ="";
		else if (hr<10) hr = "0"+hr+":";
		else hr = hr+":";
		if (min<10) min = "0"+min+":";
		else min = min+":";
		if (sec<10) sec = "0"+sec;

		return hr+min+sec;

	}

	function getTotalSec(tm)
	{
		var divTm = tm.split(":");
		//alert(divTm.length);
		var totalSec = 0;
		if (divTm.length ==3)
		{
			totalSec = parseInt(divTm[0]) *60*60;
			totalSec += parseInt(divTm[1]) *60;
			totalSec += parseInt(divTm[2]);
		}
		if (divTm.length ==2)
		{
			totalSec = parseInt(divTm[0]) *60;
			totalSec += parseInt(divTm[1]) ;
		}
		if (divTm.length ==1)
		{
			totalSec = parseInt(divTm[0]);
		}
		return totalSec;
	}
  </script>
 </head>

 <body>
  <div id="a" style="height:20px;width:50px;">12:05:23</div>
  <div id="b" style="height:20px;width:50px;" onclick="javascript:fnGetRestTime('b');">06:00</div>
  <div id="c" style="height:20px;width:50px;" onclick="javascript:fnGetRestTime('c');">45</div>
 </body>
</html>
